package com.stottlerhenke.simbionic.common.parser;

import java.util.ArrayList;

public abstract class SB_ParserAppInterface {
  /**
   * Creates an expression node describing a parse error.
   * @param msg the error message
   * @param badName indicates the invalid portion of the expression
   * @return the new expression node
   */
  public abstract SB_ExpressionNode CreateErrorNode(String msg, String badName);
  public SB_ExpressionNode CreateErrorNode(String msg){ return CreateErrorNode(msg, "");}
  /**
   * Creates a constant expression node.
   * @param value the constant value
   * @return the new expression node
   */
  public abstract SB_ExpressionNode CreateConstantNode(float value);
  public abstract SB_ExpressionNode CreateConstantNode(int value) ;
  public abstract SB_ExpressionNode CreateConstantNode(boolean value);
  public abstract SB_ExpressionNode CreateConstantNode(String value) ;
  public abstract SB_ExpressionNode CreateConstantNode(String value, boolean symbol);
  public abstract SB_ExpressionNode CreateConstantNode(double x,double y,double z);

  /**
   * Creates an expression node containing a constant array
   * @param array Vector of SB_ExpressionNode objects
   */
  public abstract SB_ExpressionNode CreateArrayNode(ArrayList array);

  /**
   * Creates an expression node that references a variable.
   * @param varName the variable name
   * @param checkName variable name will be verified if true
   * @return the new expression node
   */
  public abstract SB_ExpressionNode CreateVariableNode(String varName);

  /**
   * Creates an expression node that refers to a class. This is used for static class
   * methods. Insstances of a class will be created as variables. 
   * @param className the class name
   * @return the new expression node
   */
  public abstract SB_ExpressionNode CreateClassNode(String className);
  
  /**
   * Creates an expression node that references a function.
   * @param funcName the function name
   * @param checkName if true, the function name will be verified
   * @return the new expression node
   */
  public abstract SB_ExpressionNode CreateFunctionNode(String funcName);

  /**
   * Creates an expression node that references a class method.
   * @param instance the class instance upon which the method is  invoked
   * @param methodName the method name
   * @return the new expression node
   */
  public abstract SB_ExpressionNode CreateMethodNode(SB_ExpressionNode instance, String methodName);
  
  /**
   * Adds a single argument to the given function call.
   * @param func the function to add the argument to
   * @param arg the argument (expression) to be added
   */
  public abstract void AddArgument(SB_ExpressionNode func,SB_ExpressionNode arg);

  /**
   * Processes a completed function node, checking the number of arguments.
   * If there is an error in the function, an error node will be returned instead.
   * @param func the function to complete
   */
  public abstract EParseResult FinishFunction(SB_ObjectRefWrapper funcWrapper);

  /**
   * Creates an expression node containing a binary operation.
   * @param arg1 the left-hand argument
   * @param arg2 the right-hand argument
   * @param op the binary operator
   * @return the new expression node
   */
  public abstract SB_ExpressionNode CreateBinaryOpNode(SB_ExpressionNode arg1, SB_ExpressionNode arg2, EBinaryOp op) ;


  /**
   * Creates an expression node containing a ternary operation.
   * @param arg1 the first argument
   * @param arg2 the second argument
   * @param arg3 the third argument
   * @param op the ternary operator
   * @return the new expression node
   */
  public abstract SB_ExpressionNode CreateTernaryOpNode(SB_ExpressionNode arg1, SB_ExpressionNode arg2, SB_ExpressionNode arg3, ETernaryOp op) ;

  /**
   * Creates an expression node containing a unary operation.
   * @param arg the argument
   * @param op the unary operator
   * @return the new expression node
   */
  public abstract SB_ExpressionNode CreateUnaryOpNode(SB_ExpressionNode arg, EUnaryOp op);

  /**
   * Inform the ParserApInterface of the entire expresson currently
   * being parsed. This string can then be used in error messages.
   * 
   * @param s The entire expression being currently parsed
   */
  public void SetCompleteExpression(String s)
  {
      _currentExpression = s;
  }
  
  /**
   * 
   * @return a string representation of the complete expression being parsed
   */
  public String GetCompleteExpression() { return _currentExpression; }
  
  public SB_ParserAppInterface() {
  }

  /**
   * The complete expression currently being parsed
   */
  private String _currentExpression;
}